<?php 
include('../../Connections/KRAPPERCON.php');
$cladoc  = getVal('t_cl_doc');
$fc_ini  = getVal('t_fc_ini');
$fc_fin  = getVal('t_fc_fin');
$fd_ini  = getVal('t_fd_ini');
$fd_fin  = getVal('t_fd_fin');
$codcli  = getVal('t_codcli');
$refdoc  = getVal('t_refped');
$vehi = getVal('t_ld_vehi');
$pend = getVal('t_pend');

$wh_fc_ini = '';
$wh_fc_fin = '';
$wh_fd_ini = '';
$wh_fd_fin = '';
$wh_vehi = '';

$wh_cladoc = isNull($cladoc," and a.ClaDocID = '".$cladoc."' ");

if (isEmpty($fc_fin)){
$wh_fc_ini = isNull($fc_ini," and date(PedFecCre) = '".$fc_ini."'");
}
else{
$wh_fc_ini = isNull($fc_ini," and date(PedFecCre) >= '".$fc_ini."'");
$wh_fc_fin = isNull($fc_fin," and date(PedFecCre) <= '".$fc_fin."'");
}

//if(!isEmpty($vehi)){
$wh_vehi = isNull($vehi," and VehID = (select vh.VehID from tt_vehiculo vh where VehPlaca = '".$vehi."')");
//}

if (isEmpty($fd_fin)){
$wh_fd_ini = isNull($fd_ini," and date(PedFecCre) = '".$fd_ini."'");
}
else{
$wh_fd_ini = isNull($fd_ini," and date(PedFecCre) >= '".$fd_ini."'");
$wh_fd_fin = isNull($fd_fin," and date(PedFecCre <= '".$fd_fin."'");
}

$wh_codcli = isZeros($codcli," and b.ClientID = ".$codcli);
$wh_refdoc = isNull($refdoc," and a.PedNroPed = '".$refdoc."'");

$wh_pend = isNull($pend," and a.DetPedFac = 0 and a.PedidoDel = 0 ");

$sql = "SELECT
a.PedidoID,PedFecCre,PedFecPed,c.ClaDocID,PedSts,a.UserID,PedNroPed,MoneyID,
PedidoTxt,b.ClientID,VehID,
CondVenID,DetPedFac,PedFecVen,ClientNom,ClientApePat,ClientApeMat,ClaDocNom
FROM tt_pedido as a inner join tt_cliente as b
on a.ClientID = b.ClientID inner join tt_clasedoc as c
on a.ClaDocId = c.ClaDocID where 1 ".$wh_vehi. $wh_cladoc .$wh_fc_ini . $wh_fc_fin . $wh_fd_ini . $wh_fc_fin . $wh_codcli . $wh_refdoc . $wh_pend.";";

doEcho($sql);
/*
	t_cl_doc : GEBI('cbo_ld_cldoc').value,
	t_fc_ini : GEBI('t_ld_fcini').value,
	t_fc_fin : GEBI('t_ld_fcfin').value,	
	t_fd_ini : GEBI('t_ld_fdini').value,
	t_fd_fin : GEBI('t_ld_fdfin').value,		
	t_codcli : GEBI('t_ld_codcli').value,
	t_refped : GEBI('t_ld_refped').value
*/
?>
<table width="100%" rules="all" border="1" cellspacing="0" class="tblSort" cellpadding="0" id='tbl_qry_ped'>
<thead>
  <tr>
    <th>Clase</th>
    <th>Nro.Documento</th>
    <th>Usuario</th>
    <th>Creacion</th>
    <th>F.Docunento</th>
    <th>Veh&iacute;culo</th>
    <th>Cliente</th>
    <th>Factura</th>
    <th>Referencia</th>
   <!-- <th>Condicion</th> -->
  </tr>
  </thead>
  <tbody>
  <?php 
  $res = $mysqli->query($sql) or die($mysqli->error.__LINE__);;
  if ($res){
  	while($row = $res->fetch_assoc()){
  ?>
  <tr>
	<td><?php echo $row['ClaDocNom']?></td>
    <td><a class='a' href="#"><?php echo $row['PedidoID']; ?></a></td>
    <td><?php echo $row['UserID']?></td>
    <td><?php echo $row['PedFecCre'];?></td>
    <td><?php echo $row['PedFecPed']?></td>
    <td><?php echo $row['VehID'];?></td>
    <td><?php echo $row['ClientID'].'/'.$row['ClientNom'].' '.$row['ClientApePat'].' '.$row['ClientApeMat']; ?></td>
    <td><?php if ($row['DetPedFac']==1) echo 'X' ;?></td>
    <td><?php echo $row['PedNroPed']; ?></td>
<!--    <td><?php echo $row['CondVenID']; ?></td> -->
  </tr>
  <?php 
  	}
  $res->close();
  $mysqli->check_result();
  }
  ?>
  </tbody>
  <tfoot>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  </tfoot>
</table>

<script type="text/javascript">
    $("#tbl_qry_ped tbody tr .a").each(function(){
$(this).attr('href','#page/Procesos/MantPedidos.php?oper=view&pedido='+this.innerHTML);
});
</script>